<?php


class important extends connector {

	function important() {
		$this->softbase(true);
	}

	function onseolinklist() {
		$this->powercheck(26, 27);
		parent::start_template();

		$MinPageid = $this->fun->accept('MinPageid', 'R');

		$page_id = $this->fun->accept('page_id', 'R');

		$countnum = $this->fun->accept('countnum', 'R');
		$MaxPerPage = $this->fun->accept('MaxPerPage', 'R');
		if (empty($MaxPerPage)) {
			$MaxPerPage = $this->CON['max_list'];
		}

		$listtype = $this->fun->accept('listtype', 'R');
		$wheretext = null;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;
		if (!empty($lng)) {
			$wheretext.=' AND lng=\'' . $lng . '\'';
		}
		$isclass = $this->fun->accept('isclass', 'R');
		if (!empty($isclass)) {
			if ($isclass == 2) $isclass = 0;
			$wheretext.=' AND isclass=' . $isclass;
		}
		$isreplace = $this->fun->accept('isreplace', 'R');
		if (!empty($isreplace)) {
			if ($isreplace == 2) $isreplace = 0;
			$wheretext.=' AND isreplace=' . $isreplace;
		}
		$iswindow = $this->fun->accept('iswindow', 'R');
		if (!empty($iswindow)) {
			if ($iswindow == 2) $iswindow = 0;
			$wheretext.=' AND iswindow=' . $iswindow;
		}


		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitkey = empty($limitkey) ? 'kid' : $limitkey;

		$limitclass = $this->fun->accept('limitclass', 'R');
		$limitclass = empty($limitclass) ? 'DESC' : $limitclass;
		$db_where = " WHERE kid>0" . $wheretext;
		$db_table = db_prefix . 'keylink';
		if (!empty($countnum)) {
			$countnum = $this->db_numrows($db_table, $db_where);
			exit($countnum);
		}
		$sql = 'SELECT kid,lng,pid,keywordname,keywordtitle,hit,linkurl,iswindow,isclass,isreplace FROM ' . $db_table . $db_where . ' ORDER BY ' . $limitkey . ' ' . $limitclass . ' LIMIT ' . $MinPageid . ',' . $MaxPerPage;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$array[] = $rsList;
		}
		$this->fun->setcookie($this->fun->noncefile() . 'pgid', $page_id, 600);
		$this->ectemplates->assign('array', $array);
		$this->ectemplates->assign('sql', $sql);
		$templatesfile = ($listtype == 'tab') ? 'article/keyword_tab_list' : 'admin/admin_keylink_list';
		$this->ectemplates->display($templatesfile);
	}

	function onlisttab() {
		parent::start_template();

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? $this->CON['default_lng'] : $lng;

		$listfunction = $this->fun->accept('listfunction', 'R');

		$loadurl = "index.php?archive=seomanage&action=seolinklist&lng=$lng&isclass=1&isreplace=&iswindow=&limitkey=&limitclass=&listtype=tab";

		$inputtext = $this->fun->accept('inputtext', 'R');
		$inputtext = empty($inputtext) ? 'order' : $inputtext;
		$this->ectemplates->assign('inputtext', $inputtext);
		$this->ectemplates->assign('listfunction', $listfunction);
		$this->ectemplates->assign('loadurl', $loadurl);
		$this->ectemplates->display('article/keyword_tab');
	}

	function onkeylinkadd() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'G');
		$tab = empty($tab) ? 'true' : $tab;
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->assign('domain', $this->CON['domain']);
		$this->ectemplates->display('admin/admin_keylink_add');
	}

	function onkeylinkedit() {
		parent::start_template();
		$db_table = db_prefix . 'keylink';
		$id = $this->fun->accept('id', 'G');
		$db_where = 'kid=' . $id;
		$keyread = $this->db->fetch_first('SELECT * FROM ' . $db_table . ' WHERE ' . $db_where);

		$lnglist = $this->get_lng_array($keyread['lng']);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('tab', 'true');
		$this->ectemplates->assign('keyread', $keyread);
		$this->ectemplates->display('admin/admin_keylink_edit');
	}

	function onkeylinksave() {
		parent::start_template();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$keywordname = $this->fun->accept('keywordname', 'P');
		$keywordtitle = $this->fun->accept('keywordtitle', 'P');
		$keywordtitle = empty($keywordtitle) ? $keywordname : $keywordtitle;
		$linkurl = $this->fun->accept('linkurl', 'P');
		$linkurl = empty($linkurl) ? $this->CON['domain'] : $linkurl;
		$iswindow = $this->fun->accept('iswindow', 'P');
		$iswindow = empty($iswindow) ? 0 : $iswindow;
		$isreplace = $this->fun->accept('isreplace', 'P');
		$isreplace = empty($isreplace) ? 0 : $isreplace;
		$lng = $this->fun->accept('lng', 'P');
		$lng = empty($lng) ? $this->CON['default_lng'] : $lng;
		$db_table = db_prefix . 'keylink';
		if ($inputclass == 'add') {
			$this->powercheck(26, 28);
			$db_field = 'lng,pid,keywordname,keywordtitle,linkurl,iswindow,isclass,isreplace';
			$db_values = "'$lng',50,'$keywordname','$keywordtitle','$linkurl',$iswindow,1,$isreplace";
			$this->db->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			$this->writelog($this->lng['seomanage_add_log'], $this->lng['log_extra_ok'] . ' keywordname=' . $keywordname);
			$this->dbcache->clearcache('keylink_array_' . $lng, true);
			exit('true');
		} else {
			$this->powercheck(26, 55);
			$id = $this->fun->accept('id', 'P');
			$db_where = 'kid=' . $id;
			$db_set = "keywordname='$keywordname'";
			$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$this->writelog($this->lng['seomanage_edit_log'], $this->lng['log_extra_ok'] . ' keywordname=' . $keywordname . ' id=' . $id);
			$this->dbcache->clearcache('keylink_array_' . $lng, true);
			exit('true');
		}
	}

	function ondelkey() {
		$this->powercheck(26, 54);
		$db_table = db_prefix . 'keylink';
		$selectinfoid = $this->fun->accept('selectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$db_where = "kid=$infoarray[$i]";
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where);
		}
		$this->writelog($this->lng['seomanage_del_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('keylink_array', true);
		exit('true');
	}

	function onkeysort() {
		$this->powercheck(26, 55);
		$db_table = db_prefix . 'keylink';
		$id = $this->fun->accept('infoid', 'P');
		$pid = $this->fun->accept('pid', 'P');
		$idArray = explode(',', $id);
		$pidArray = explode(',', $pid);
		foreach ($idArray as $key => $value) {
			if (!empty($value)) {
				$db_where = "kid=$value";
				$pid = intval($pidArray[$key]);
				$db_set = "pid=$pid";
				$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			}
		}
		$this->writelog($this->lng['seomanage_log_sort'], $this->lng['log_extra_ok']);
		$this->dbcache->clearcache('keylink_array', true);
		exit('true');
	}

	function onsetting() {
		$this->powercheck(26, 56);
		$db_table = db_prefix . 'keylink';
		$selectinfoid = $this->fun->accept('selectinfoid', 'P');
		$selectinfoid = $selectinfoid . '0';
		if (empty($selectinfoid)) exit('false');
		$value = $this->fun->accept('value', 'P');
		$dbname = $this->fun->accept('dbname', 'P');
		$db_set = "$dbname=$value";
		$db_where = "kid IN ( $selectinfoid )";
		$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
		$this->writelog($this->lng['seomanage_log_istype'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('keylink_array', true);
		exit('true');
	}

	function onseolinktypelist() {
		$this->powercheck(26, 247);
		parent::start_template();

		$MinPageid = $this->fun->accept('MinPageid', 'R');

		$page_id = $this->fun->accept('page_id', 'R');

		$countnum = $this->fun->accept('countnum', 'R');
		$MaxPerPage = $this->fun->accept('MaxPerPage', 'R');
		if (empty($MaxPerPage)) {
			$MaxPerPage = $this->CON['max_list'];
		}

		$listtype = $this->fun->accept('listtype', 'R');
		$wheretext = null;

		$lng = $this->fun->accept('lng', 'R');
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;
		if (!empty($lng)) {
			$wheretext.=' AND lng=\'' . $lng . '\'';
		}


		$limitkey = $this->fun->accept('limitkey', 'R');
		$limitkey = empty($limitkey) ? 'ktid' : $limitkey;

		$limitclass = $this->fun->accept('limitclass', 'R');
		$limitclass = empty($limitclass) ? 'DESC' : $limitclass;
		$db_where = " WHERE ktid>0" . $wheretext;
		$db_table = db_prefix . 'keylink_type';
		if (!empty($countnum)) {
			$countnum = $this->db_numrows($db_table, $db_where);
			exit($countnum);
		}
		$sql = 'SELECT ktid,lng,keytypename,keyworklist FROM ' . $db_table . $db_where . ' ORDER BY ' . $limitkey . ' ' . $limitclass . ' LIMIT ' . $MinPageid . ',' . $MaxPerPage;
		$rs = $this->db->query($sql);
		while ($rsList = $this->db->fetch_assoc($rs)) {
			$array[] = $rsList;
		}
		$this->fun->setcookie($this->fun->noncefile() . 'pgid', $page_id, 600);
		$this->ectemplates->assign('array', $array);
		$this->ectemplates->assign('sql', $sql);
		$templatesfile = ($listtype == 'tab') ? 'article/keyword_tab_list' : 'admin/admin_keylinktype_list';
		$this->ectemplates->display($templatesfile);
	}

	function onkeylinktypeadd() {
		parent::start_template();
		$tab = $this->fun->accept('tab', 'G');
		$tab = empty($tab) ? 'true' : $tab;
		$lng = empty($lng) ? ($this->CON['is_alonelng'] && !empty($this->CON['home_lng'])) ? $this->CON['home_lng'] : $this->CON['default_lng'] : $lng;

		$lnglist = $this->get_lng_array($lng);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('tab', $tab);
		$this->ectemplates->display('admin/admin_keylinktype_add');
	}

	function onkeylinktypeedit() {
		parent::start_template();
		$db_table = db_prefix . 'keylink_type';
		$id = $this->fun->accept('id', 'G');
		$db_where = 'ktid=' . $id;
		$keyread = $this->db->fetch_first('SELECT * FROM ' . $db_table . ' WHERE ' . $db_where);

		$lnglist = $this->get_lng_array($keyread['lng']);
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('tab', 'true');
		$this->ectemplates->assign('keyread', $keyread);
		$this->ectemplates->display('admin/admin_keylinktype_edit');
	}

	function onkeylinktypesave() {
		parent::start_template();
		$inputclass = $this->fun->accept('inputclass', 'P');
		$keytypename = $this->fun->accept('keytypename', 'P');
		$keytitle = $this->fun->accept('keytitle', 'P');
		$keyworklist = $this->fun->accept('keyworklist', 'P');
		$description = $this->fun->accept('description', 'P');
		$lng = $this->fun->accept('lng', 'P');
		$lng = empty($lng) ? $this->CON['default_lng'] : $lng;
		$db_table = db_prefix . 'keylink_type';
		if ($inputclass == 'add') {
			$this->powercheck(26, 247);
			$db_field = 'lng,keytypename,keytitle,keyworklist,description';
			$db_values = "'$lng','$keytypename','$keyworklist','$description'";
			$this->db->query('INSERT INTO ' . $db_table . ' (' . $db_field . ') VALUES (' . $db_values . ')');
			$this->writelog($this->lng['seomanage_type_add_log'], $this->lng['log_extra_ok'] . ' keytypename=' . $keytypename);
			$this->dbcache->clearcache('keylinktype_array_' . $lng, true);
			$delindex = admin_ROOT . "html/". $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
			if (file_exists($delindex)) {
				$this->fun->delfile($delindex);
			}
			exit('true');
		} else {
			$this->powercheck(26, 55);
			$id = $this->fun->accept('id', 'P');
			$db_where = 'ktid=' . $id;
			$db_set = "keytypename='$keytypename',keytitle='$keytitle',keyworklist='$keyworklist',description='$description'";
			$this->db->query('UPDATE ' . $db_table . ' SET ' . $db_set . ' WHERE ' . $db_where);
			$this->writelog($this->lng['seomanage_type_edit_log'], $this->lng['log_extra_ok'] . ' keytypename=' . $keytypename . ' id=' . $id);
			$this->dbcache->clearcache('keylinktype_array_' . $lng, true);
			$this->dbcache->clearcache('keylinktype_view_' . $id, true);
			$delindex = admin_ROOT . "html/". $this->CON['entrance_file'] .'.'.$this->CON['file_fileex'];
			if (file_exists($delindex)) {
				$this->fun->delfile($delindex);
			}
			exit('true');
		}
	}

	function ondelkeytype() {
		$this->powercheck(26, 54);
		$db_table = db_prefix . 'keylink_type';
		$selectinfoid = $this->fun->accept('selectinfoid', 'P');
		if (empty($selectinfoid)) exit('false');
		$infoarray = explode(',', $selectinfoid);
		$count = count($infoarray) - 1;
		if ($count <= 0) exit('false');
		for ($i = 0; $i < $count; $i++) {
			$db_where = "ktid=$infoarray[$i]";
			$this->db->query('DELETE FROM ' . $db_table . ' WHERE ' . $db_where);
		}
		$this->writelog($this->lng['seomanage_type_del_log'], $this->lng['log_extra_ok'] . ' id=' . $selectinfoid);
		$this->dbcache->clearcache('keylinktype_array', true);
		exit('true');
	}

}
?>